#include <iostream>
#include <algorithm>
using namespace std;

const int N = 1e6 + 10;

int n;

struct node{
	int l,r;
}a[N];

bool cmp(node& x,node& y){
	return x.l < y.l;
}

int main(){
	cin >> n;
	for(int i = 1;i <= n;i++){
		cin >> a[i].l >> a[i].r;
	}
	sort(a + 1,a + 1 + n,cmp);
	int ri = a[1].r;
	int ret = 1;
	for(int i = 2;i <= n;i++){
		if(a[i].l < ri){
			ri = min(a[i].r,ri);
		}
		else{
			ret++;
			ri = a[i].r;
		}
	}
	cout << ret << endl;
	return 0;
}
